package cn.stylefeng.guns.modular.order.util;

import cn.stylefeng.guns.modular.order.model.result.TbFreightResult;
import cn.stylefeng.guns.modular.order.service.TbFreightService;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

public class Util {


      @Autowired
      private TbFreightService tbFreightService;
    /**
     * 运费计算
     *  weight 重量
     *  area  目的地
     *  return 运费,到达时间
     */

    public String  freight(String area, BigDecimal weight ){


        TbFreightResult tbFreightResult=tbFreightService.freight(area);
        //首重价格
        BigDecimal jiage =tbFreightResult.getFirstPrice();
        //首重
        BigDecimal firstWeight=tbFreightResult.getFirstWeight();
        //续重
        BigDecimal continuesWeight=tbFreightResult.getContinuesWeight();
        //续重价格
        BigDecimal continuesPrice=tbFreightResult.getContinuesPrice();
        //比较
      if(weight.compareTo(firstWeight)==1){
          //减法 算出超出首重的重量
          BigDecimal   zhoangliang =weight.subtract(firstWeight);
          //除法  ,乘法
          jiage= zhoangliang.divide(continuesWeight).multiply(continuesPrice).add(jiage);

      }
      return jiage.toString()+","+tbFreightResult.getArrivalTime();
    }


    /**
     * 运费,数量,单价,税率
     * 实付金额
     */
    public    BigDecimal  pay(BigDecimal jiage,int quantity,String money,BigDecimal tax) {
        BigDecimal bigDecimal = new BigDecimal(money);
        BigDecimal bigDecimal1 = new BigDecimal(quantity);
        //数量*单价
        BigDecimal bigDecimal2=  bigDecimal.multiply(bigDecimal1);
        //税价
        tax=bigDecimal2.multiply(tax);

        return  jiage.add(tax).add(bigDecimal2);
    }

}
